var Util = {
  getQuery: function(name) {
    var searchArr = location.search.slice(1).split('&')
    var cache = {}
    searchArr.map(function(search, index) {
      var keyVal = search.split('=')
      cache[keyVal[0]] = keyVal[1]
    })
    if (name) {
      return cache[name]
    }
    return cache
  },
  trim: function(str) {
    return str.replace(/(^\s+)|(\s+$)/g, '')
  },
  extend: function() {
    var args = arguments,
      target = args[0],
      len = args.length,
      i = 1,
      deep = false,
      tar, source, option, key
    if (typeof target === 'boolean') {
      deep = target
      target = args[i++]
    }
    for (; i < len; i++) {

      option = args[i]

      for (key in option) {
        tar = target[key]
        source = option[key]
        if (deep && typeof source === 'object') {
          if (!tar) {
            tar = Object.prototype.toString.call(source) === '[object Array]' ? [] : {}
          }
          target[key] = assign(deep, tar, source)
        } else {
          target[key] = source
        }
      }
    }
    return target
  },
  alert: function(msg, timeout) {
    var div = document.getElementsByClassName('xu-alert')[0]
    if (div) {
      div.innerHTML = msg
      div.style.display = 'block'
    } else {
      div = document.createElement('div')
      div.className = 'xu-alert'
      div.innerHTML = msg
      document.body.appendChild(div)
    }
    setTimeout(function() {
      div.style.display = 'none'
    }, timeout || 2000)
  },
  localData: function (key, dataObj) {
    //  本地存储规则： json格式存储，设置空字串删掉存储
    if (typeof dataObj == 'undefined') {
      var data = localStorage.getItem(key)
      if (data) {
        data = JSON.parse(data)
      }
      return data
    } else {
      localStorage.setItem(key, JSON.stringify(dataObj))
    }
  }
}

var $$ = Util